package com.wyz.socket.core.base.packet;

import com.wyz.socket.core.utils.Log;

import java.io.IOException;
import java.io.InputStream;

public abstract class AbstractSendPacket<T extends InputStream> extends Packet<T> {

    protected boolean isCancel;

    public boolean isCancel() {
        return isCancel;
    }

    public void cancel() {
        this.isCancel = true;
    }

    /**
     * 获取还可以用的数据大小
     * @return
     */
    public int availabel() {
        InputStream stream = open();
        try {
            int availabel = stream.available();
            if (availabel < 0) {
                return 0;
            }
            return availabel;
        } catch (IOException e) {
            Log.printException("AbstractsendPacket ", " stream availabel is error " , e);
        }
        return 0;
    }
}
